#!/usr/bin/env python
# coding: utf-8

import re
import gzip
import sys
from itertools import islice

GO_TYPES = ['P', 'F', 'C']

def parse_go_funcs(s):
    d = {}
    for tf in s.split():
        t,f = tf.split(':')
        assert t not in d
        d[t] = set(f.split(','))
    return d

def is_entry_equal(d1, d2):
    if d1.keys() != d2.keys():
        return False
    for t in d1:
        if d1[t].difference(d2[t]) and d2[t].difference(d1[t]):
            return False
    return True


def main():
    compare_type = sys.argv[1].strip()
    assert compare_type in ['exact', 'entry']
    real_funcs = set([line.strip() for line in sys.stdin])
    
    pw_size = len(real_funcs)
    results = [(0, pw_size)]

    line_id = 0
    for line in gzip.open(sys.argv[2]):
        line = line.strip()
        if not line:
            continue
        line_id += 1
        pred_func = line.split('\t')[1].strip()
        if compare_type == 'exact':
            if pred_func in real_funcs:
                real_funcs.discard(pred_func)
                results.append((line_id, len(real_funcs)))
        elif compare_type == 'entry':
            pfd = parse_go_funcs(pred_func)
            for rf in real_funcs:
                rfd = parse_go_funcs(rf)
                if is_entry_equal(rfd, pfd):
                    real_funcs.discard(rf)
                    results.append((line_id, len(real_funcs)))
                    break
        if not real_funcs or line_id > max(500, pw_size):
            break

    return ' '.join('%d:%d' % (i,n) for i,n in results)

print main()

